Helpful Information
 
 
Category: Perl
Perl -> PHP

Hi,

I need to do some pattern matching in PHP. I need to find all the HTTP: and MAILTO: in a body of text and add <A> tags around them so they are clickable. I did this in Perl:

foreach(@body) {s/(http:|www|)([^s^>^]]+)/<A HREF="$1$2" TARGET=_blank>$1$2</A>/i};

and

foreach(@body) {s/(mailto:[^s]+@[^s^>^]]+)/<A HREF="$1">$1</A>/i};

which works fine. (suggest a better method?) How can I do the same in PHP?

Thanks for your help!

i would look here...
http://php.net/manual/html/ref.regex.html#AEN34622

regular expressions are basically the same in PHP and Perl as far as i can tell.

oh yeah... this is a good explanation for what your looking for....
http://phpbuilder.com/columns/dario19990616.php3


hope that helps
ccbcreg



[This message has been edited by ccbcreg (edited November 27, 2000).]

ccbcreg:

Thanks for all your links! I didn't know I could do the same in PHP. The tutorial you pointed to was very helpful too!

I have a qusetion tough.... I wanted to match , and the only way I got it to work was (8 of them!). I was wondering why that is... I thought i only needed 4 (the case with Perl).

Anyway, Thanks!


[This message has been edited by syin (edited November 27, 2000).]

Try this,

but I didn't test it, it should come pretty close though!

eregi_replace('mailto:([a-z0-9]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[_a-z0-9-]+)+)","<a href="mailto:1">1</a>",$text);

eregi_replace("http://([^[]*)","<a href="http://1" TARGET="_new">1</a>",$text);


Wid regards to the problem, try enclosing your regex in single inverted commas eg: '[:alnum:]'.

You should be able to use afterwards.

Lataz,

Releasedj


[This message has been edited by releasedj (edited November 28, 2000).]










privacy (GDPR)